home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_09_06
/
9n06057b
< prev
next >
Wrap
Text File
|
1991-02-23
|
2KB
|
97 lines
// class ThingList -- a list of things
//
// Version 1.0 -- 2/25/91
//
// Michael Kelly -- Author
//
#pragma warn -pia // nix "Possibly incorrect assignment"
#include "th_list.hpp"
static Thing dummy_thing;
ThingList::~ThingList()
{
while( head ) {
rover = head;
head = head->next;
delete rover;
rover = NULL;
}
}
int ThingList::add( Thing &some_thing )
{
if( ! ( rover = head ) ) {
if( ! ( head = new thing_node ) )
return 0;
head->this_thing = &some_thing;
head->next = NULL;
}
else {
while( rover->next )
rover = rover->next;
if( ! ( rover->next = new thing_node ) )
return 0;
rover = rover->next;
rover->this_thing = &some_thing;
rover->next = NULL;
}
++nodes;
return 1;
}
Thing* ThingList::operator[]( unsigned index )
{
if(
( ! ( rover = head ) ) ||
( index >= nodes )
)
return &dummy_thing;
while( index-- ) {
if( ! rover->next )
return &dummy_thing;
rover = rover->next;
}
return rover->this_thing;
}
unsigned ThingList::iterate( void ( Thing::*funcptr )() )
{
if( ! ( rover = head ) )
return 0;
do {
if( rover->this_thing )
(rover->this_thing->*funcptr)();
}
while( rover = rover->next );
return nodes;
}
unsigned ThingList::iterate( int ( Thing::*funcptr )() )
{
unsigned successes = 0;
if( ! ( rover = head ) )
return 0;
do {
if( rover->this_thing )
successes += (rover->this_thing->*funcptr)();
}
while( rover = rover->next );
return successes;
}
#pragma warn .pia // restore warning to default state